﻿je_heavenly_kingdom_main = {
	icon = "gfx/interface/icons/event_icons/event_religion.dds"

	is_shown_when_inactive = {
		exists = c:CHI
		THIS = c:CHI
		NOT = {
			country_has_state_religion = rel:god_society
		}
		
	}

	possible = {
		is_subject = no
		any_scope_state = {
    		state_region = { is_homeland = cu:han NOT = { is_homeland = cu:manchu } }
			OR = {
				any_neighbouring_state = {
					is_treaty_port = yes
					owner = {
						OR = {
							religion = rel:protestant
							religion = rel:reformed
							religion = rel:anglican
						}
					}
				}
				is_coastal = yes
			}
			any_neighbouring_state = { state_region = { is_homeland = cu:han NOT = { is_homeland = cu:manchu } } }
			is_incorporated = yes
			any_scope_pop = {
				OR ={
					has_pop_religion = god_society
				}
				
			}
			is_capital = no
			state_region = { 
				OR = {
					is_homeland = cu:han 
					is_homeland = cu:hakka 
				}
			}
			turmoil > 0.15
		}
	}

	immediate = {
		random_scope_state = {
			limit = {
    			state_region = { is_homeland = cu:han NOT = { is_homeland = cu:manchu } }
				OR = {
					any_neighbouring_state = {
						is_treaty_port = yes
						owner = {
							OR = {
								religion = rel:protestant
								religion = rel:reformed
								religion = rel:anglican
							}
						}
					}
					is_coastal = yes
				}
				any_neighbouring_state = { state_region = { is_homeland = cu:han NOT = { is_homeland = cu:manchu } } }
				is_incorporated = yes
				any_scope_pop = {
					has_pop_religion = god_society
				}
				is_capital = no
				state_region = { 
					OR = {
						is_homeland = cu:han 
						is_homeland = cu:hakka 
					}
				}
				turmoil > 0.15
			}
			add_modifier = {
				name = god_worshippers
				months = short_modifier_time
			}
		}
		trigger_event = {
			id = heavenly.2
		}
	}

	on_monthly_pulse = {
		random_events = {
			5 = 0
			1 = heavenly.3
		}
	}

	complete = {
		NOT = {
			any_scope_state = {
				has_modifier = god_worshippers
			}
		}
	}

	fail = {
		any_scope_state = {
			has_modifier = god_worshippers
			count >= 4
		}
		any_scope_state = {
			has_modifier = god_worshippers
			any_scope_pop = {
				has_pop_religion = god_society
			}
			turmoil >= 0.15
		}
		NOT = { has_law = law_type:law_total_separation }
	}

	on_fail = {
		trigger_event = {
			id = heavenly.4
		}
	}

	weight = 10000
	should_be_pinned_by_default = yes
}

je_taiping = {
	icon = "gfx/interface/icons/event_icons/event_revolt.dds"

	complete = {
		custom_tooltip = {
			text = taiping_destroyed
			hidden_trigger = {
				NOT = {
					exists = c:TPG
				}
			}
		}
	}

	immediate = {
		c:TPG = {
			save_scope_as = taiping_scope
		}
	}
	
	on_complete = {
		trigger_event = { id = heavenly.5 days = 0 }
		hidden_effect = {
			remove_modifier = taiping_taiping_rebellion
		}
	}

	fail = {
		exists = c:TPG
		has_truce_with = c:TPG
	}

	on_fail = {
		if = {
			limit = { has_journal_entry = je_warlord_china }
			post_notification = warlord_china_explosion_point_add
			change_variable = {
				name = china_warlord_explosion
				add = 10
			}
		}

		hidden_effect = {
			remove_modifier = taiping_taiping_rebellion
			c:TPG = {
				remove_modifier = taiping_taiping_rebellion
			}
		}
	}

	weight = 1000
	should_be_pinned_by_default = yes

	inheritable = no
}

je_taiping_revolution = {
	icon = "gfx/interface/icons/event_icons/event_military.dds"

	complete = {
		OR = {
			custom_tooltip = {
				text = china_destroyed
				hidden_trigger = {
					NOT = {
						exists = c:CHI
					}
				}
			}
			AND = {
				exists = c:CHI
				has_truce_with = c:CHI		
			}
		}
		
	}

	immediate = {
		c:CHI = {
			save_scope_as = china_scope
		}
	}

	on_complete = {
		trigger_event = { id = heavenly.6 days = 0 }
		custom_tooltip = {
			text = rebellion_effects_remove
			remove_modifier = taiping_taiping_rebellion
			every_interest_group = {
				limit = {
					has_modifier = taiping_taiping_revolution
				}
				remove_modifier = taiping_taiping_revolution
			}
		}
		
	}

	fail = {
		NOT = {
			exists = c:TPG
		}
	}

	weight = 1000
	should_be_pinned_by_default = yes

	inheritable = no
}